package zgc.demo.provider.mapper;

import org.springframework.stereotype.Repository;
import zgc.demo.provider.entity.Goods;

import java.util.ArrayList;
import java.util.List;

@Repository
public class GoodsMapper {
    private static List<Goods> goodsList;

    static {
        goodsList = new ArrayList<>();
        Goods goods1 = new Goods("HW001", "华为手机", 2999.0, 10000);
        Goods goods2 = new Goods("HW002", "华为平板", 5999.0, 10000);
        Goods goods3 = new Goods("HW003", "华为笔记本", 9999.0, 10000);
        Goods goods4 = new Goods("XM001", "小米手机", 2999.0, 10000);
        Goods goods5 = new Goods("XM002", "小米平板", 3999.0, 10000);
        goodsList.add(goods1);
        goodsList.add(goods2);
        goodsList.add(goods3);
        goodsList.add(goods4);
        goodsList.add(goods5);
    }

    public Goods getGoodsById(String goodsId) {

        if (goodsId.equals("HW001")) {
            return goodsList.get(0);
        } else if (goodsId.equals("HW002")) {
            return goodsList.get(1);
        } else if (goodsId.equals("HW003")) {
            return goodsList.get(2);
        } else if (goodsId.equals("XM001")) {
            return goodsList.get(3);
        } else {
            return goodsList.get(4);
        }

    }

    public List<Goods> getGoodsLikeName(String goodsName) {

        if (goodsName.contains("华为")) {
            List<Goods> huaweiList = new ArrayList<>();
            huaweiList.add(goodsList.get(0));
            huaweiList.add(goodsList.get(1));
            huaweiList.add(goodsList.get(2));
            return huaweiList;
        } else {
            List<Goods> xiaomiList = new ArrayList<>();
            xiaomiList.add(goodsList.get(3));
            xiaomiList.add(goodsList.get(4));
            return xiaomiList;
        }
    }

    public List<Goods> getList() {
        return goodsList;
    }
}
